﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NorthwindEmployees
{
    public partial class Details : System.Web.UI.Page
    {
        private Employee LoadEmployee()
        {
            Employee employee = null;
            NorthwindEntities context = new NorthwindEntities();
            var id = Request.Params["EmployeeID"];
            int idInt = 0;
            try
            {
                idInt = int.Parse(id);
            }
            catch (Exception)
            {
                return null;
            }

            using (context)
            {
                employee = context.Employees.FirstOrDefault(e => e.EmployeeID == idInt);
            }

            return employee;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
            {
                return;
            }

            List<Employee> employees = new List<Employee>();
            Employee employee = LoadEmployee();
            employees.Add(employee);

            this.EmployeeDetails.DataSource = employees;
            this.EmployeeDetails.DataBind();
        }
    }
}